package com.hgx.su.example.common.springboot.mybatis.plus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgx.su.common.pure.dto.CommonPageReqDto;
import com.hgx.su.common.pure.dto.CommonPageResDto;
import com.hgx.su.common.pure.dto.ResultResponse;
import com.hgx.su.example.common.springboot.mybatis.plus.entity.User;
import com.hgx.su.example.common.springboot.mybatis.plus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * author: HGX
 * DateTime: 2021-02-04 16:37
 */
@RestController
@RequestMapping("/")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("getAll1")
    public List<User> getAll1() {
        return userService.getAll1();
    }

    @GetMapping("getAll2")
    public List<User> getAll2() {
        return userService.getAll2();
    }

    @GetMapping("getAll")
    public List<User> getAll() {
        List<User> all1 = userService.getAll1();
        List<User> all2 = userService.getAll2();
        List<User> list = new ArrayList<>();
        list.addAll(all1);
        list.addAll(all2);
        return list;
    }

    @GetMapping("pageHelper")
    public ResultResponse<CommonPageResDto<User>> pageHelper() {
        return ResultResponse.ok(userService.pageHelper(new CommonPageReqDto()));
    }

    @GetMapping("pagePlus")
    public Page<User> pagePlus() {
        return userService.pagePlus();
    }


}
